home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 7 / FM Towns Free Software Collection 7.iso / t_os / artemis / artsrc2 / ginit.asm < prev    next >
Assembly Source File  |  1993-11-30  |  7KB  |  357 lines

  1. ;    私製ライブラリ・グラフィック篇
  2. ;    (c) MATSUUCHI Ryosuke in Dec,1992
  3. ;
  4. ;    ginit.asm : 初期化
  5. ;
  6. ;    1992. 6.11 ... 6.13
  7. ;    1992.12.28(Sun)
  8.  
  9.         .386p
  10.  
  11.         public    _ginit, ginit, _egbwork
  12.         public    _callEGB, __SetVramSeg
  13.         public    __AddVramBase_ebx
  14.         public    __AddVramBase_esi
  15.         public    __AddVramBase_edi
  16.         public    __getpadrs
  17.         public    __getpscrmod
  18.         public    _egbwork, _scrmod, _wrtpage, _nowscrmod
  19.         public    _vscrbase, _vscrmod
  20.         public    _gramscr, gramscr
  21.  
  22.         extrn    EGB_work : dword
  23.  
  24.         assume    cs:cseg, ds:dseg
  25.  
  26.  
  27.  
  28. dseg segment dword 'DATA'
  29.  
  30.         align    4
  31. __dmy__        db    4 dup (0)
  32. _egbwork    db    1536 dup (0)    ;EGBライブラリ用ワークエリア
  33. _scrmod        dd    0        ;ページ0の画面モード
  34.         dd    0        ;ページ1の画面モード
  35. _vscrmod    dd    0,0,0,0        ;仮想画面(0~3)の画面モード
  36. _vscrbase    dd    0,0,0,0        ;仮想画面(0~3)のベースオフセット
  37. _nowscrmod    dd    0        ;現在ページの画面モード
  38. _wrtpage    dd    0        ;現在の書き込みページ番号
  39.                     ;(bit7=1 なら、仮想画面を意味する)
  40.  
  41.  
  42. __scrbase    dd    0,40000h    ;実画面各ページのベースオフセット
  43. __scrsel    dd    104h,104h,104h    ;各画面モードのセレクタ値
  44.         dd    104h,104h,104h
  45.         dd    104h,104h,104h
  46.         dd    104h,104h,104h
  47.         dd    10ch,10ch,10ch
  48.         dd    10ch,10ch,10ch
  49.         dd    10ch,10ch,10ch
  50.  
  51. dseg ends
  52.  
  53.  
  54.  
  55. cseg segment dword 'CODE'
  56.  
  57. ;---------------------------------------------------------------
  58. ;    _callEGB : グラフィックBIOSの呼び出し
  59. ;        in  AH     機能コード
  60. ;            DS:ESI パラメータ領域のアドレス
  61. ;---------------------------------------------------------------
  62.  
  63.         align    4
  64.  
  65. _callEGB    proc
  66.         push    edi
  67.         push    ds
  68.         pop    gs
  69.         mov    edi,offset _egbwork
  70.         push    dword ptr 0110h
  71.         pop    fs
  72.         call    pword ptr fs:[20h]
  73.         pop    edi
  74.         ret
  75. _callEGB    endp
  76.  
  77. ;---------------------------------------------------------------
  78. ;    _ginit : Rio's Graphic Library の初期化
  79. ;        in  none
  80. ;        out none
  81. ;
  82. ;    void    ginit()
  83. ;---------------------------------------------------------------
  84.  
  85. ginit        proc    near
  86. _ginit:
  87.         push    eax
  88.         push    ecx
  89.         xor    ax,ax
  90.         mov    ecx,1536
  91.         call    _callEGB
  92.         mov    eax,3
  93.         mov    [_nowscrmod],eax
  94.         mov    [_scrmod+0],eax
  95.         mov    [_scrmod+4],eax
  96.         xor    al,al
  97.         mov    byte ptr [_wrtpage],al
  98.         mov    eax,offset _egbwork
  99.         mov    [EGB_work],eax
  100.         pop    ecx
  101.         pop    eax
  102.         ret
  103. ginit        endp
  104.  
  105. ;-------------------------------------------------------------------------
  106. ;    __setvramseg : es を、現在の書き込みページのセグメントに設定する
  107. ;               ※(私製ライブラリの内部ルーチン)
  108. ;        in  none
  109. ;        out none
  110. ;        reg es
  111. ;-------------------------------------------------------------------------
  112.  
  113. __SetVramSeg    proc near
  114.         push    eax
  115.         mov    eax,[_wrtpage]
  116.         bt    eax,7
  117.         jc    #vscr
  118.             ;実画面の場合
  119.             mov    eax,[_scrmod + eax*4]
  120.             cmp    eax,11
  121.             jg    #1
  122.                 mov    eax,104h  ;モード 1~11: セレクタ 104h
  123.                 jmp    #2
  124.             #1:
  125.                 mov    eax,10ch  ;モード 12~ : セレクタ 10Ch
  126.             #2:
  127.             mov    es,ax
  128.             jmp    #end
  129.         #vscr:
  130.             ;仮想画面の場合 : 単に es←ds を行うだけ
  131.             push    ds
  132.             pop    es
  133.         #end:
  134.         pop    eax
  135.         ret
  136. __SetVramSeg    endp
  137.  
  138. ;-------------------------------------------------------------------------
  139. ;    __AddVramBase_ebx
  140. ;        ebx に、現在の書き込みページのベースオフセットを加算する
  141. ;        (私製ライブラリの内部ルーチン)
  142. ;        in  none
  143. ;        out none
  144. ;        reg ebx
  145. ;-------------------------------------------------------------------------
  146.  
  147. __AddVramBase_ebx proc near
  148.         push    eax
  149.         mov    eax,[_wrtpage]
  150.         bt    eax,7
  151.         jc    #0
  152.             or    eax,eax
  153.             jz    #1
  154.                 add    ebx,40000h
  155.             #1:
  156.             jmp    #2
  157.         #0:
  158.             and    eax,7fh
  159.             add    ebx,[_vscrbase + eax*4]
  160.         #2:
  161.         pop    eax
  162.         ret
  163. __AddVramBase_ebx endp
  164.  
  165.  
  166. ;-------------------------------------------------------------------------
  167. ;    __AddVramBase_edi
  168. ;        edi に、現在の書き込みページのベースオフセットを加算する
  169. ;        (私製ライブラリの内部ルーチン)
  170. ;        in  none
  171. ;        out none
  172. ;        reg ebx
  173. ;-------------------------------------------------------------------------
  174.  
  175. __AddVramBase_edi proc near
  176.         push    eax
  177.         mov    eax,[_wrtpage]
  178.         bt    eax,7
  179.         jc    #0
  180.             or    eax,eax
  181.             jz    #1
  182.                 add    edi,40000h
  183.             #1:
  184.             jmp    #2
  185.         #0:
  186.             and    eax,7fh
  187.             add    edi,[_vscrbase + eax*4]
  188.         #2:
  189.         pop    eax
  190.         ret
  191. __AddVramBase_edi endp
  192.  
  193.  
  194. ;-------------------------------------------------------------------------
  195. ;    __AddVramBase_esi
  196. ;        esi に、現在の書き込みページのベースオフセットを加算する
  197. ;        (私製ライブラリの内部ルーチン)
  198. ;        in  none
  199. ;        out none
  200. ;        reg ebx
  201. ;-------------------------------------------------------------------------
  202.  
  203. __AddVramBase_esi proc near
  204.         push    eax
  205.         mov    eax,[_wrtpage]
  206.         bt    eax,7
  207.         jc    #0
  208.             or    eax,eax
  209.             jz    #1
  210.                 add    esi,40000h
  211.             #1:
  212.             jmp    #2
  213.         #0:
  214.             and    eax,7fh
  215.             add    esi,[_vscrbase + eax*4]
  216.         #2:
  217.         pop    eax
  218.         ret
  219. __AddVramBase_esi endp
  220.  
  221.  
  222. ;-------------------------------------------------------------------------
  223. ;    __getpscrmod
  224. ;        指定ページの画面モードを得る
  225. ;        (私製ライブラリの内部ルーチン)
  226. ;        in  eax     : ページ(bit7=1 → 仮想画面)
  227. ;        out eax     : 画面モード
  228. ;-------------------------------------------------------------------------
  229.  
  230.  
  231. __getpscrmod    proc    near
  232.         bt    eax,7
  233.         jc    #0
  234.         mov    eax,[_scrmod + eax*4]    ;eax ← 画面モード
  235.         ret
  236. #0:        and    eax,7fh
  237.         mov    eax,[_vscrmod + eax*4]
  238.         ret
  239. __getpscrmod    endp
  240.  
  241.  
  242. ;-------------------------------------------------------------------------
  243. ;    __getpadrs
  244. ;        指定ページの指定座標のアドレスのセレクタとオフセットを得る
  245. ;        (私製ライブラリの内部ルーチン)
  246. ;        in  eax     : ページ(bit7=1 → 仮想画面)
  247. ;            ebx,ecx : 座標
  248. ;        out eax     : セレクタ
  249. ;            ebx     : オフセット
  250. ;        reg eax,ebx
  251. ;-------------------------------------------------------------------------
  252.  
  253. __getpadrs    proc    near
  254.         push    edx
  255.         push    esi
  256.         push    edi
  257.         bt    eax,7
  258.         jc    #0
  259.             ;(実画面ページの場合)
  260.             mov    edi,[__scrbase + eax*4]    ;edi ←ベースオフセット
  261.             mov    eax,[_scrmod + eax*4]    ;eax ← 画面モード
  262.             mov    edx,[__scrsel + eax*4]    ;edx ← セレクタ
  263.             jmp    #1
  264.         #0:
  265.             ;(仮想画面ページの場合)
  266.             and    eax,7fh
  267.             mov    edi,[_vscrbase+eax*4]    ;edi ←ベースオフセット
  268.             mov    eax,[_vscrmod+eax*4]    ;eax ←画面モード
  269.             sub    edx,edx            ;edx ←セレクタ
  270.             mov    dx,ds
  271.         #1:
  272.         cmp    eax,4
  273.         jg    #2
  274.             ;画面モード3~4の場合(1~2は無視)
  275.             mov    esi,ecx    ;esi=y*512+(x/2)
  276.             shl    esi,9
  277.             mov    eax,ebx
  278.             shr    eax,1
  279.             add    esi,eax
  280.             jmp    #3
  281.         #2:
  282.         cmp    eax,8
  283.         jg    #4
  284.             ;画面モード5~8の場合
  285.             mov    esi,ecx    ;edi=y*512+x*2
  286.             shl    esi,9
  287.             lea    esi,[esi+ebx*2]
  288.             jmp    #3
  289.         #4:
  290.         cmp    eax,11
  291.         jg    #5
  292.             ;画面モード9~11の場合
  293.             mov    esi,ecx    ;esi=y*1024+x*2
  294.             shl    esi,10
  295.             lea    esi,[esi+ebx*2]
  296.             jmp    #3
  297.         #5:
  298.         cmp    eax,14
  299.         jg    #6
  300.             ;画面モード12~14の場合
  301.             mov    esi,ecx    ;esi=y*1024+x
  302.             shl    esi,10
  303.             add    esi,ebx
  304.             jmp    #3
  305.         #6:
  306.             ;画面モード15~の場合
  307.             mov    esi,ecx
  308.             shl    esi,10
  309.             lea    esi,[esi+ebx*2]
  310.         #3:
  311.         add    edi,esi
  312.         mov    ebx,edi
  313.         mov    eax,edx
  314.         pop    edi
  315.         pop    esi
  316.         pop    edx
  317.         ret
  318. __getpadrs    endp
  319.  
  320.  
  321. ;---------------------------------------------------------------
  322. ;    _gramscr : 仮想画面の設定
  323. ;        in  eax : 設定する仮想画面ページ (0x80 | page)
  324. ;            ebx : どの画面モードにするか
  325. ;            ecx : 画面バッファへのポインタ (256K / 512K bytes)
  326. ;    void gramscr(page, mode, buf)
  327. ;---------------------------------------------------------------
  328.  
  329. _gramscr    proc
  330.         push    eax
  331.         and    eax,7fh
  332.         mov    [_vscrmod+eax*4],ebx
  333.         mov    [_vscrbase+eax*4],ecx
  334.         pop    eax
  335.         ret
  336. _gramscr    endp
  337.  
  338.  
  339. gramscr        proc
  340.         push    ebx
  341.     #para    equ    8
  342.         mov    eax,[esp+#para+0]
  343.         mov    ebx,[esp+#para+4]
  344.         mov    ecx,[esp+#para+8]
  345.         call    _gramscr
  346.         pop    ebx
  347.         ret
  348. gramscr        endp
  349.  
  350.  
  351.  
  352.  
  353.  
  354. cseg ends
  355.  
  356. end
  357.